﻿using System;
using SilentWebsite.Model.Contracts;
using SilentWebsite.Web;

namespace SilentWebsite.Model.Services
{
    public class AccountServiceClient : IAccountService
    {
        public event EventHandler<ActionEventArg> Completed;
        protected virtual void OnCompleted(ActionEventArg e)
        {
            EventHandler<ActionEventArg> handler = Completed;
            if (handler != null)
                handler(this, e);
        }

        public void CreateAccount(User user)
        {
            ServicesUnitOfWork.Current.Entity.CreateAccount(user,
                x => OnCompleted(new ActionEventArg { Status = Status.Created }), true);
        }
        public void UpdateAccount(User user)
        {
            ServicesUnitOfWork.Current.Entity.UpdateAccount(user,
                x => OnCompleted(new ActionEventArg { Status = Status.Updated }), true);
        }
        public void DeleteAccount(User user)
        {
            ServicesUnitOfWork.Current.Entity.DeleteAccount(user,
                x => OnCompleted(new ActionEventArg { Status = Status.Deleted }), true);
        }
    }
}
